package com.dimples.dd.system.mapper;

import com.dimples.dd.common.pojo.PageResult;
import com.dimples.dd.mybatis.core.query.LambdaQueryWrapperX;
import com.dimples.dd.system.model.entity.Oauth2RegisteredClientDO;
import com.dimples.dd.system.model.query.OAuth2ClientPageQuery;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface Oauth2RegisteredClientMapper extends com.dimples.dd.mybatis.core.mapper.BaseMapperX<Oauth2RegisteredClientDO> {

    /**
     * 根据客户端id查询客户端信息
     *
     * @param clientId 客户端id
     * @return Oauth2RegisteredClientDO
     */
    default Oauth2RegisteredClientDO selectByClientId(String clientId) {
        return selectOne(Oauth2RegisteredClientDO::getClientId, clientId);
    }

    /**
     * 分页查询客户端信息
     *
     * @param pageQuery 分页查询参数
     * @return PageResult
     */
    default PageResult<Oauth2RegisteredClientDO> selectPage(OAuth2ClientPageQuery pageQuery) {
        return selectPage(pageQuery, new LambdaQueryWrapperX<Oauth2RegisteredClientDO>()
                .likeIfPresent(Oauth2RegisteredClientDO::getClientName, pageQuery.getClientName())
                .eqIfPresent(Oauth2RegisteredClientDO::getStatus, pageQuery.getStatus())
                .orderByDesc(Oauth2RegisteredClientDO::getId));
    }
}